﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Entities;

namespace Interview_Prov.Controls
{
    public partial class Select_Interview_Ctl : System.Web.UI.UserControl
    {
        public List<string> InterviewTitles { get; set; }
        private Business.BusinessLogic bll = new Business.BusinessLogic();
        public event EventHandler OkButtonClicked;
        public string SelectedInterviewTitle { get; private set; }
        public int SelectedInterviewID { get; private set; }
        private List<Interview> ints;

        protected void Page_Load(object sender, EventArgs e)
        {
            ints = bll.GetInterviewsForRole(Global.UserLevel == null ? "user" : Global.UserLevel);
            if (!IsPostBack)
            {
                this.InterviewTitles = ints.Select((x) => (x.Title)).ToList();
                if (InterviewTitles.Count == 0)
                {
                    ddl_interviews.Enabled = false;
                    btn_ok.Enabled = false;
                }
                DataBind();
            }
        }

        protected void btn_ok_Click(object sender, EventArgs e)
        {
            this.SelectedInterviewTitle = ddl_interviews.SelectedValue;
            this.SelectedInterviewID = ints[ddl_interviews.SelectedIndex].ID;

            if (OkButtonClicked != null)
                OkButtonClicked(this, new EventArgs());
        }
    }
}